package com.softline.documentsmall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softline.documentsmall.dao.RelateJournalArticalMapper;
import com.softline.documentsmall.entity.RelateJournalArtical;
import com.softline.documentsmall.ret.BusinessErrorEnum;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.RelateJournalArticalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @Author wph
 * @Date 2021/2/3 15:29
 */
@Service
@Slf4j
public class RelateJournalArticalServiceImpl extends ServiceImpl<RelateJournalArticalMapper, RelateJournalArtical> implements RelateJournalArticalService{

    @Autowired
    private  RelateJournalArticalMapper relateJournalArticalMapper;

    @Override
    public ReturnVO insert(RelateJournalArtical relateJournalArtical) {
        try {
            relateJournalArtical.setLanguage("cn");
            this.save(relateJournalArtical);
        } catch (Exception e) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
        return ReturnVOUtils.success();
    }

    @Override
    public ReturnVO updateRelateBookById(RelateJournalArtical relateJournalArtical) {
        try {
            //有的更新 没有不需要
            relateJournalArticalMapper.updateByPrimaryKeySelective(relateJournalArtical);
        } catch (Exception e) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
        return ReturnVOUtils.success();
    }

    @Override
    public RelateJournalArtical selectById(int id) {
        return relateJournalArticalMapper.selectById(id);
    }


    @Override
    public List<RelateJournalArtical> selectList(String title, Integer dictionaryId, Integer pageNo, Integer pageSize) {
        return relateJournalArticalMapper.selectListLocal(title, dictionaryId, (pageNo- 1) * pageSize , pageSize);
    }

    @Override
    public long selectCount(String title,Integer dictionaryId) {
        return relateJournalArticalMapper.selectLocalCount(title,dictionaryId);
    }
}
